<template>
  <div class="content">
    <div class="head">
      <div class="recom">推荐关注</div>
      <div class="more">
        <span>查看更多</span>
        <van-icon name="arrow" />
      </div>
    </div>
    <ul class="doctors">
      <li class="doctor" v-for="item in docList" :key="item.id">
        <img class="avatar" :src="item.avatar" />
        <div class="name">{{item.name}}</div>
        <div class="hospital">
          <p class="hospitalName">{{item.hospitalName}} {{item.depName}}</p>
          <p class="positionalTitles">{{item.positionalTitles}}</p>
        </div>
        <button class="attention" @click="onLike(item)">
          {{ item.likeFlag ? "已关注" : "+ 关注" }}
        </button>
      </li>
    </ul>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { likeKnowledge, getDocList } from '@/api'

// 获取医生列表
const docList = ref([])
const fetchDocList = async () => {
  const { data: { rows } } = await getDocList({
    current: 1,
    pageSize: 5
  })
  docList.value = rows
}
fetchDocList()

// 关注操作
const onLike = async (item) => {
  await likeKnowledge({
    id: item.id,
    type: 'doc'
  })
  const index = docList.value.findIndex(el => el.id === item.id)
  if (docList.value[index].likeFlag === 0) {
    docList.value[index].likeFlag = 1
  } else {
    docList.value[index].likeFlag = 0
  }
}
</script>

<style lang="scss" scoped>
.content {
  padding: 30px 0 30px 30px;
  font-size: 26px;
  .head {
    display: flex;
    justify-content: space-between;
    margin-bottom: 30px;
    padding-right: 30px;
    .more {
      color: #c3c3c5;
    }
  }
  .doctors {
    display: flex;
    overflow-x: auto;
    &::-webkit-scrollbar{
        display: none;
    }
    .doctor {
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      align-items: center;
      margin-right: 30px;
      padding: 30px;
      border-radius: 36px;
      width: 266px;
      height: 370px;
      background-color: #fff;
      .avatar {
        width: 120px;
        border-radius: 50%;
      }
      .hospital{
        width: 206px;
        font-size: 22px;
        color: #c3c3c5;
        text-align: center;
        .hospitalName {
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
        }
      }
      .attention {
        padding: 0 35px;
        border: 0;
        border-radius: 30px;
        background-color: #16c2a3;
        height: 56px;
        font-size: 24px;
        color: #fff;
      }
    }
  }
}
</style>
